package onion.molingo2o.activity.request;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;

import com.easemob.chatuidemo.ui.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import onion.molingo2o.R;
import onion.molingo2o.adapter.OnionAdapter;
import onion.molingo2o.bean.SignInfo;
import onion.molingo2o.utils.UIUtils;
import onion.molingo2o.views.swipemenulistview.SwipeMenu;
import onion.molingo2o.views.swipemenulistview.SwipeMenuCreator;
import onion.molingo2o.views.swipemenulistview.SwipeMenuItem;
import onion.molingo2o.views.swipemenulistview.SwipeMenuListView;

/**
 * Created by Administrator on 2015/11/11.
 */
public class Reque2ResponListActivity extends BaseActivity {
    private SwipeMenuListView listView;
    OnionAdapter adapter;
    List<SignInfo> list=new ArrayList<>();

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        setContentView(R.layout.activity_req2resplist);
        initTitle("", "报名列表", "需求详情");
        listView= (SwipeMenuListView) findViewById(R.id.list);
        adapter=new OnionAdapter(this,R.layout.item_req_simple,list,new String[]{"name","time","content","type"},new String[]{"getAvatar"});
        adapter.setCallBack(new OnionAdapter.CallBack() {
            @Override
            public void onGetView(View view, int postion) {
                //处理type
            }
        });
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(onItemClickListener);
        SwipeMenuCreator creator = new SwipeMenuCreator() {

            @Override
            public void create(SwipeMenu menu) {
                // Create different menus depending on the view type
                switch (menu.getViewType()) {
                    case 0:
                        createMenu1(menu);
                        break;
//                    case 1:
//                        createMenu2(menu);
//                        break;
//                    case 2:
//                        createMenu3(menu);
//                        break;
                }
            }
        };
        listView.setMenuCreator(creator);
        listView.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
                showToast("点击了"+position+"/"+index);
                if(index==1)
                    startActivity(new Intent(Reque2ResponListActivity.this,OrderCreateActivity.class));
                return false;
            }
        });
        getTest();
    }
    private void createMenu1(SwipeMenu menu) {
        SwipeMenuItem item1 = new SwipeMenuItem(
                getApplicationContext());
        item1.setBackground(new ColorDrawable(Color.rgb(0xE5, 0x18,
                0x5E)));
        item1.setWidth(UIUtils.dp2px(90));
        item1.setTitle("聊天");
        item1.setTitleColor(Color.WHITE);
        item1.setTitleSize(18);
//        item1.setIcon(R.drawable.ic_action_favorite);
        menu.addMenuItem(item1);
        SwipeMenuItem item2 = new SwipeMenuItem(
                getApplicationContext());
        item2.setBackground(new ColorDrawable(Color.rgb(0xF7, 0xBD,
                0x97)));
        item2.setWidth(UIUtils.dp2px(90));
        item2.setTitleColor(Color.WHITE);
        item2.setTitleSize(18);
        item2.setTitle("约定");
//        item2.setIcon(R.drawable.ic_action_good);
        menu.addMenuItem(item2);
        SwipeMenuItem item3 = new SwipeMenuItem(
                getApplicationContext());
        item3.setBackground(new ColorDrawable(Color.rgb(0xC9, 0xC9,
                0xCE)));
        item3.setWidth(UIUtils.dp2px(90));
        item3.setTitleColor(Color.WHITE);
        item3.setTitleSize(18);
        item3.setTitle("忽略");
//        item2.setIcon(R.drawable.ic_action_good);
        menu.addMenuItem(item3);
    }
    @Override
    protected View.OnClickListener getTopClickListener() {
        return new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(Reque2ResponListActivity.this,RequestDetailActivity.class));
            }
        };
    }

    private void getTest() {
        for(int i=0;i<4;i++){
            list.add(new SignInfo("http://h.hiphotos.baidu.com/image/pic/item/ac4bd11373f0820245c568ed4ffbfbedaa641b88.jpg","闪电侠","909","就是快","2015-11-11",0));
        }
        adapter.notifyDataSetChanged();
    }

    AdapterView.OnItemClickListener onItemClickListener=new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
          startActivity(new Intent(Reque2ResponListActivity.this,ResponDetailActivity.class));
        }
    };
}
